package ui.panels.primary.second;

import gameEngine.experiments.Experiment;

import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import ui.flowManager.expirimentProperties.ExperimentProperties;
import ui.panels.commands.NextCommand;
import auxiliary.AuxiliaryClass;
/**
 * Listener for second panel
 * @author vladimir
 *
 */
public class SecondPanelListener implements ActionListener{
	private SecondPanel 			secondPanel = null;
	private ExperimentProperties 	props = null;
	
	private final int 				numOfGames = 1;
	
	public SecondPanelListener(SecondPanel panel, ExperimentProperties props)
	{
		this.secondPanel = panel;
		this.props = props;
	}
	
	/**
	 * 
	 */
	public void actionPerformed(ActionEvent arg0) {

		String inputTurns = secondPanel.getjTextField1().getText();
		String inputRepeats = secondPanel.getRepeatsField().getText();
		String nameInput = secondPanel.getNameField().getText();
		
		
		//case one of the inputs is empty
		if (inputTurns.equals("") || (inputRepeats.equals("")) || nameInput.equals(""))
		{
			return;
		}
		
		if(AuxiliaryClass.isNumber(inputTurns) && AuxiliaryClass.isNumber(inputRepeats))
		{
			// number of turns that the user typed
			int numTurns = Integer.parseInt(inputTurns);		
			int numRepeats = Integer.parseInt(inputRepeats);
			
			String observation = (String) secondPanel.getObservationDrop().getSelectedItem();	
			//create one game
			props.setGames(numOfGames);	
			props.setExperimentName(nameInput);
			
			props.setGameData(numOfGames, numTurns, numRepeats, observation);
			
			//create the next panel 
			NextCommand nextCommand = new NextCommand();
			nextCommand.execute();
		}
		else
		{
			//do nothing
		}

	}
}

